<template>
  <div class="app_content">
      <el-form :inline="true" ref="queryForm" :model="queryParams" class="demo-form-inline" :size="size" v-if="showSearch">
      <el-form-item label="菜单名称" prop="menuName">
      <el-input v-model="queryParams.menuName" clearable placeholder="菜单名称" style="width: 240px"/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
      <el-select v-model="queryParams.status" placeholder="菜单状态" clearable style="width: 240px">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="querySubmit">
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-search'"/>
          搜索</el-button>
        <el-button   @click="resetSubmit">
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-redo'"/>
          重置</el-button>
      </el-form-item>
      </el-form>
       <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            :size="size"
            @click="handleAdd"
            v-hasRole="['system:menu:add']"
          >
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-add-one'"/>
          新增</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
        <el-button
          type="info"
          plain
          :icon="Switch"
          :size="size"
          @click="toggleExpandAll"
        >展开/折叠</el-button>
      </el-col> -->
        <!-- <RightToolbar :showSearch="showSearch" @queryTable="getList" :columns="columns"/> -->
        <RightToolbar :showSearch="showSearch" @queryTable='getList' @showSearchClick='showSearchClick' :columns="columns"/>
      </el-row>
      <el-table  :border="$border"  :default-expand-all="isExpandAll" :height="maxHeight" row-key="menuId" :tree-props="{children: 'children', hasChildren: 'hasChildren'}" v-loading="loading" :data="tableData"   style="width: 100%" @selection-change="handleSelectionChange"  :size="size"
      >
      <el-table-column prop="menuName" label="菜单名称" key="menuName" :show-overflow-tooltip="true" width="160" v-if="columns[0].visible"></el-table-column>
      <el-table-column prop="icon" key="icon" label="图标" align="center" width="100" v-if="columns[1].visible">
        <template #default="scope">
          <component
              class="menu-icon"
              v-if="scope.row.icon"
              theme="outline"
              size="14"
              strokeWidth="3"
              :is="scope.row.icon"
            />
        </template>
      </el-table-column>
      <el-table-column prop="orderNum" key="orderNum" label="排序" width="60" v-if="columns[2].visible"></el-table-column>
      <el-table-column prop="perms" key="perms" label="权限标识" :show-overflow-tooltip="true" v-if="columns[3].visible"></el-table-column>
      <el-table-column prop="component" key="component" label="组件路径" :show-overflow-tooltip="true" v-if="columns[4].visible"></el-table-column>
      <el-table-column prop="status" key="status" label="状态" :formatter="statusFormat" width="80" v-if="columns[5].visible">
      </el-table-column>
      <el-table-column label="创建时间"  prop="createTime" show-overflow-tooltip key="createTime"  v-if="columns[6].visible"/>
      <el-table-column label="操作" fixed="right" align="center"  width="300px">
      <template #default="scope">
        <el-button :size="size" type="success"  text @click="handleEdit(scope.row)" v-hasRole="['system:menu:edit']"
          >
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-edit-one'"/>
          修改</el-button>
          <el-button :size="size" type="success" text @click="handleAdd(scope.row)" v-hasRole="['system:menu:add']"
          >
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-add-one'"/>
          新增</el-button>
          <el-button
          :size="size"
          type="danger"
          text
          @click="handleDelete(scope.row)"
          v-hasRole="['system:menu:remove']"
          >
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-delete-five'"/>
          删除</el-button>
      </template>
      </el-table-column>
      </el-table>
 
      <!-- 添加或修改菜单对话框 -->
    <!-- <el-dialog  v-model="open" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false" width="680px" append-to-body draggable :fullscreen="fullscreen">
      <template #header="{ titleId, titleClass }">
      <div class="my-header">
        <span :id="titleId" :class="titleClass">{{title}}</span>
        <div>
          <component
        style="cursor:pointer;line-height: 24px;margin-right:10px;"
        v-if="fullscreen==false"
              @click="fullscreen=true"
              class="menu-icon"
              theme="outline"
              size="14"
              strokeWidth="3"
              :is="'icon-full-screen-one'"
            />
            <component
            v-else
        style="cursor:pointer;line-height: 24px;margin-right:10px;"
              @click="fullscreen=false"
              class="menu-icon"
              theme="outline"
              size="14"
              strokeWidth="3"
              :is="'icon-off-screen-one'"
            />
        <component
        style="cursor:pointer;line-height: 24px;"
              @click="cancel"
              class="menu-icon"
              theme="outline"
              size="14"
              strokeWidth="3"
              :is="'icon-close'"
            />
        </div>
        
      </div>
    </template>
      <el-form ref="formDataRef" :model="formData" :rules="rules" label-width="100px" :size="size">
        <el-row>
          <el-col :span="24">
            <el-form-item label="上级菜单" prop="parentId">
              
              <el-tree-select
                  v-model="formData.parentId"
                  :data="menuOptions"
                  check-strictly
                  :props="treeProps"
                  :render-after-expand="false"
                />
             
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="菜单类型" prop="menuType">
              <el-radio-group v-model="formData.menuType">
                <el-radio label="M">目录</el-radio>
                <el-radio label="C">菜单</el-radio>
                <el-radio label="F">按钮</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="formData.menuType != 'F'">
            <el-row :gutter="30">
              <el-col :span="16">
                <el-form-item label="菜单图标" prop="icon">
                  <el-input v-model="formData.icon" disabled placeholder="请选择图标">
                    <template #append >
                      <el-button  style="cursor:pointer;" @click="openicon" >点击选择图标</el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="图标显示：" >
                <component
                    v-if="formData.icon"
                    class="menu-icon"
                    theme="outline"
                    size="20"
                    strokeWidth="3"
                    :is="formData.icon"
                />
                <span v-else >无</span>
              </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="12">
            <el-form-item label="菜单名称" prop="menuName">
              <el-input v-model="formData.menuName" placeholder="请输入菜单名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number v-model="formData.orderNum" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="isFrame">
              <template #label>
                <el-tooltip content="选择是外链则路由地址需要以`http(s)://`开头" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                是否外链
              </template>
              <el-radio-group v-model="formData.isFrame">
                <el-radio label="0">是</el-radio>
                <el-radio label="1">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="path">
              <template #label>
                <el-tooltip content="访问的路由地址，如：`user`，如外网地址需内链访问则以`http(s)://`开头" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                路由地址
              </template>
              <el-input v-model="formData.path" placeholder="请输入路由地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType == 'C'">
            <el-form-item prop="component">
              <template #label>
                <el-tooltip content="访问的组件路径，如：`system/user/index`，默认在`views`目录下" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                组件路径
              </template>
              <el-input v-model="formData.component" placeholder="请输入组件路径" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'M'">
            <el-form-item prop="perms">
              <el-input v-model="formData.perms" placeholder="请输入权限标识" maxlength="100" />
              <template #label>
                <el-tooltip content="控制器中定义的权限字符，如：@PreAuthorize(`@ss.hasPermi('system:user:list')`)" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                权限字符
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType == 'C'">
            <el-form-item prop="query">
              <el-input v-model="formData.query" placeholder="请输入路由参数" maxlength="255" />
              <template #label>
                <el-tooltip content='访问路由的默认传递参数，如：`{"id": 1, "name": "ry"}`' placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                路由参数
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType == 'C'">
            <el-form-item prop="isCache">
              <template #label>
                <el-tooltip content="选择是则会被`keep-alive`缓存，需要匹配组件的`name`和地址保持一致" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                是否缓存
              </template>
              <el-radio-group v-model="formData.isCache">
                <el-radio label="0">缓存</el-radio>
                <el-radio label="1">不缓存</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="visible">
              <template #label>
                <el-tooltip content="选择隐藏则路由将不会出现在侧边栏，但仍然可以访问" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                显示状态
              </template>
              <el-radio-group v-model="formData.visible">
                <el-radio
                  v-for="dict in showOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="status">
              <template #label>
                <el-tooltip content="选择停用则路由将不会出现在侧边栏，也不能被访问" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                菜单状态
              </template>
              <el-radio-group v-model="formData.status">
                <el-radio
                  v-for="dict in statusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div  class="dialog-footer">
        <el-button type="primary" @click="submitForm" :size="size">确 定</el-button>
        <el-button @click="cancel" :size="size">取 消</el-button>
      </div>
      </template>
      
    </el-dialog> -->

    <el-drawer
      :title="title"
      v-model="open"
      direction="rtl"
      destroy-on-close
      size="60%"
      :close-on-click-modal="false"
    >
    <el-form ref="formDataRef" :model="formData" :rules="rules" label-width="100px" :size="size">
        <el-row>
          <el-col :span="24">
            <el-form-item label="上级菜单" prop="parentId">
              <!-- <TreeSelect
              v-if="treeis"
              ref="myTreeSelect"
              :modelValue="formData.parentId"
              :treeData="menuOptions"
              :defaultProps="{'id':'menuId','label':'menuName','children':'children'}"
              ></TreeSelect> -->
              <el-tree-select
                  v-model="formData.parentId"
                  :data="menuOptions"
                  check-strictly
                  :props="treeProps"
                  :render-after-expand="false"
                />
              <!-- <treeselect
                v-model="formData.parentId"
                :options="menuOptions"
               
                placeholder="选择上级菜单"
              />  :normalizer="normalizer"
                :show-count="true" -->
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="菜单类型" prop="menuType">
              <el-radio-group v-model="formData.menuType">
                <el-radio label="M">目录</el-radio>
                <el-radio label="C">菜单</el-radio>
                <el-radio label="F">按钮</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="formData.menuType != 'F'">
            <el-row :gutter="30">
              <el-col :span="16">
                <el-form-item label="菜单图标" prop="icon">
                  <el-input v-model="formData.icon" disabled placeholder="请选择图标">
                    <template #append >
                      <el-button  style="cursor:pointer;" @click="openicon" >点击选择图标</el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="图标显示：" >
                <component
                    v-if="formData.icon"
                    class="menu-icon"
                    theme="outline"
                    size="20"
                    strokeWidth="3"
                    :is="formData.icon"
                />
                <span v-else >无</span>
              </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="12">
            <el-form-item label="菜单名称" prop="menuName">
              <el-input v-model="formData.menuName" placeholder="请输入菜单名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number v-model="formData.orderNum" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="isFrame">
              <template #label>
                <el-tooltip content="选择是外链则路由地址需要以`http(s)://`开头" placement="top">
                  <!-- <i  >?</i> -->
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                是否外链
              </template>
              <el-radio-group v-model="formData.isFrame">
                <el-radio label="0">是</el-radio>
                <el-radio label="1">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="path">
              <template #label>
                <el-tooltip content="访问的路由地址，如：`user`，如外网地址需内链访问则以`http(s)://`开头" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                路由地址
              </template>
              <el-input v-model="formData.path" placeholder="请输入路由地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType == 'C'">
            <el-form-item prop="component">
              <template #label>
                <el-tooltip content="访问的组件路径，如：`system/user/index`，默认在`views`目录下" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                组件路径
              </template>
              <el-input v-model="formData.component" placeholder="请输入组件路径" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'M'">
            <el-form-item prop="perms">
              <el-input v-model="formData.perms" placeholder="请输入权限标识" maxlength="100" />
              <template #label>
                <el-tooltip content="控制器中定义的权限字符，如：@PreAuthorize(`@ss.hasPermi('system:user:list')`)" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                权限字符
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType == 'C'">
            <el-form-item prop="query">
              <el-input v-model="formData.query" placeholder="请输入路由参数" maxlength="255" />
              <template #label>
                <el-tooltip content='访问路由的默认传递参数，如：`{"id": 1, "name": "ry"}`' placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                路由参数
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType == 'C'">
            <el-form-item prop="isCache">
              <template #label>
                <el-tooltip content="选择是则会被`keep-alive`缓存，需要匹配组件的`name`和地址保持一致" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                是否缓存
              </template>
              <el-radio-group v-model="formData.isCache">
                <el-radio label="0">缓存</el-radio>
                <el-radio label="1">不缓存</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="visible">
              <template #label>
                <el-tooltip content="选择隐藏则路由将不会出现在侧边栏，但仍然可以访问" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                显示状态
              </template>
              <el-radio-group v-model="formData.visible">
                <el-radio
                  v-for="dict in showOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formData.menuType != 'F'">
            <el-form-item prop="status">
              <template #label>
                <el-tooltip content="选择停用则路由将不会出现在侧边栏，也不能被访问" placement="top">
                  <div style=" margin-top: 1px;"><icon-info theme="outline" size="16" fill="#999" /></div>
                </el-tooltip>
                菜单状态
              </template>
              <el-radio-group v-model="formData.status">
                <el-radio
                  v-for="dict in statusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div  class="dialog-footer">
          <el-button type="primary" @click="submitForm" :size="size">
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-correct'"/>
          确 定</el-button>
        <el-button @click="cancel" :size="size">
          <component :theme="iconTheme" :size="iconSize" :strokeWidth="iconStrokeWidth" :is="'icon-return'"/>
          取 消</el-button>
      </div>
      </template>
  </el-drawer>

    <el-drawer :close-on-click-modal="false" size="70%" title="选择菜单图标" v-model="iconOpen" :direction="'ltr'">
    <IconMyPark @iconValue="iconValue"></IconMyPark>
    </el-drawer>
    <!-- <el-dialog    :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false" width="80%" append-to-body draggable :fullscreen="iconfullscreen">
      <template #header="{close,titleId, titleClass }">
      <div class="my-header">
        <span :id="titleId" :class="titleClass">图标选择</span>
        <div>
          <component
        style="cursor:pointer;line-height: 24px;margin-right:10px;"
        v-if="iconfullscreen==false"
              @click="iconfullscreen=true"
              class="menu-icon"
              theme="outline"
              size="14"
              strokeWidth="3"
              :is="'icon-full-screen-one'"
            />
            <component
            v-else
        style="cursor:pointer;line-height: 24px;margin-right:10px;"
              @click="iconfullscreen=false"
              class="menu-icon"
              theme="outline"
              size="14"
              strokeWidth="3"
              :is="'icon-off-screen-one'"
            />
        <component
        style="cursor:pointer;line-height: 24px;"
              @click="close"
              class="menu-icon"
              theme="outline"
              size="14"
              strokeWidth="3"
              :is="'icon-close'"
            />
        </div>
        
      </div>
    </template>
    <IconMyPark @iconValue="iconValue"></IconMyPark>
    </el-dialog> -->
  
  </div>
  
</template>

<script  >
import RightToolbar from '@/components/RightToolbar/index.vue';
import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu";
// // import the component
// import Treeselect from 'vue3-treeselect'
// // import the styles
// import 'vue3-treeselect/dist/vue3-treeselect.css'
import IconMyPark from './iconMyPark.vue'
// import TreeSelect from '@/components/TreeSelectMenu/index.vue'

import { computed, ref ,reactive,onMounted,getCurrentInstance,toRefs,nextTick} from 'vue'
import { useStore } from 'vuex';
import { useI18n } from 'vue-i18n';
import {
Delete,
Edit,
Plus,
Switch,
Close,
QuestionFilled

} from '@element-plus/icons-vue'

export default defineComponent({
  // register the component
  components:{
    IconMyPark,
    QuestionFilled
  },
setup(){
  const { proxy } = getCurrentInstance();//关键代码
  const queryForm=ref()
  const formDataRef=ref()
  const { t } = useI18n();
  const myTreeSelect=ref(null)
  const store = useStore();
  const staticData=reactive({
    // 表单参数
    formData: {
      menuId: undefined,
      parentId: 0,
      menuName: undefined,
      icon: undefined,
      menuType: "M",
      orderNum: undefined,
      isFrame: "1",
      isCache: "0",
      visible: "0",
      status: "0"
    },
    treeProps:{
        label: 'menuName', // 设置节点显示的字段，默认为 'label'
        children: 'children', // 设置子节点的字段，默认为 'children'
        value:'menuId',
        isLeaf: 'leaf', // 设置判断是否叶子节点的字段，默认为 'isLeaf'
      },
    // 表单校验
    rules: {
      menuName: [
        { required: true, message: "菜单名称不能为空", trigger: "blur" }
      ],
      icon:[
      { required: true, message: "菜单图标不能为空", trigger: "blur" }
      ],
      orderNum: [
        { required: true, message: "菜单顺序不能为空", trigger: "blur" }
      ],
      path: [
        { required: true, message: "路由地址不能为空", trigger: "blur" }
      ]
    },
    maxHeight:store.getters['setting/mode']=='horizontal'?document.body.clientHeight - 200:store.getters['setting/isFullScreen']!=false ?document.body.clientHeight - 360:document.body.clientHeight - 260 ,
    treeis:false,
    //是否全屏
    fullscreen:false,
    iconfullscreen:false,
    // 弹出层标题
    title: "",
      // 是否显示弹出层
    open: false,
    iconOpen:false,
    single:true,
    multiple:true,
    showSearch:true,
    background:false,
    disabled :false,
    search:'',
    tableData:[],
    // 菜单树选项
    menuOptions: [],
    // 日期范围
    dateRange: [],
    //显示数据字典
    showOptions:[],
    // 菜单状态数据字典
    statusOptions: [],
    // 是否展开，默认全部展开
    isExpandAll: false,
    // 重新渲染表格状态
    loading: true,
    // 查询参数
    queryParams: {
      menuName: undefined,
      status: undefined
    },
    total:0,
    loading:true, 
    ExportHead:{
      id: "编号",
      name: "角色名称",
      age: "权限字符",
      xb: "显示顺序",
      des: "状态",
      date: "创建时间",
    },
    // 列信息
    columns: [
      { key: 0, label: `菜单名称`, visible: true },
      { key: 1, label: `图标`, visible: true },
      { key: 2, label: `排序`, visible: true },
      { key: 3, label: `权限标识`, visible: true },
      { key: 4, label: `组件路径`, visible: true },
      { key: 5, label: `状态`, visible: true },
      { key: 6, label: `创建时间`, visible: true },
      
    ],
  })

  const size = computed(() => {
        return store.getters['setting/size'];
  });

  const small =computed(() => {
    return size.value=='small'?true:false
  });

  const filterTableData = computed(() =>
    staticData.tableData.filter(
      (data) =>
        !staticData.search.value ||
        data.name.toLowerCase().includes(staticData.search.value.toLowerCase())
    )
  )
  /**
   * 重置表单效验方法
   */
  const resetForm = (formEl) => {
    if (!formEl.value) return
    formEl.value.resetFields()
  }

  onMounted(() => {
      proxy.$getDicts("sys_normal_disable").then(response => {
        staticData.statusOptions = response.data;
      });
      proxy.$getDicts("sys_show_hide").then(response => {
        staticData.showOptions = response.data;
      });
      proxy.getTreeselect();
      proxy.getList()
    })
    
    const cancel = (formEl) => {
      //myTreeSelect.value.Subcancel()
      staticData.treeis=false
      staticData.open = false;
      proxy.reset();
  }
  const methods = {
    /**
     * 获取数据
     */
     getList(){
        staticData.loading = true;
        listMenu(staticData.queryParams).then(
          response => {
            staticData.tableData = proxy.$handleTree(response.data, "menuId");
            staticData.loading = false;
          }
      );
     },
     
    /**
     * 菜单状态字典翻译
     */
    statusFormat(row, column) {
      if (row.menuType == "F") {
        return "";
      }
      const data=proxy.$selectDictLabel(staticData.statusOptions, row.status)
      let stateClass
      // if(data=='正常'){
      //   stateClass='status_success'
      // }else{
      //   stateClass='status_error'
      // }
      
      return data;
    },
    /**
     * 获取icon
     */
    iconValue(val){
      staticData.formData.icon=val
      staticData.iconOpen=false
    },
    /**
     * 表单重置
     */
    reset() {
      staticData.formData = {
        menuId: undefined,
        parentId: 0,
        menuName: undefined,
        icon: undefined,
        menuType: "M",
        orderNum: undefined,
        isFrame: "1",
        isCache: "0",
        visible: "0",
        status: "0"
      };
      resetForm(formDataRef)
      
    },
    
     /** 展开/折叠操作 */
     toggleExpandAll() {
      staticData.loading = false;
      nextTick(() => {
        staticData.isExpandAll = !staticData.isExpandAll;
        staticData.loading = true;
      });
    },
    
    
    /**
     * 打开图标按钮
     */
    openicon(){
      staticData.iconfullscreen=false
      staticData.iconOpen=true
      
      
    },

    /** 
     * 查询菜单下拉树结构
     *  
     **/
    getTreeselect() {
      listMenu().then(response => {
        staticData.menuOptions = [];
        const menu = { menuId: 0, menuName: '主类目', children: [] };
        menu.children = proxy.$handleTree(response.data, "menuId");
        staticData.menuOptions.push(menu);
      });
    },
    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.menuId,
        label: node.menuName,
        children: node.children
      };
    },
     /**
      * 显示或隐藏搜索条件
      **/
     showSearchClick(data){
       staticData.showSearch=data
     },
     /**
      * 表格选择框事件
      */
     handleSelectionChange(){

    },
    /**
     * 新增
     */
     handleAdd(row){
      staticData.fullscreen=false
      proxy.reset();
      staticData.treeis=true
      if (row != null && row.menuId) {
        staticData.formData.parentId = row.menuId;
      } else {
        staticData.formData.parentId = 0;
      }
      staticData.open = true;
      staticData.title = "添加菜单";
    },
   
    /**
     * 编辑
     */
    handleEdit(row){
      staticData.fullscreen=false
      proxy.reset();
      
      getMenu(row.menuId).then(response => {
        nextTick(() => {
          staticData.formData = response.data;
          staticData.treeis=true
      });
        
        staticData.open = true;
        staticData.title = "修改菜单";
      });
    },
    /**
     * 删除
     */
    handleDelete(row){
      ElMessageBox.confirm('是否确认删除名称为"' + row.menuName + '"的数据项？', t('confirm.title'), {
          confirmButtonText: t('btn.confirm'),
          cancelButtonText: t('btn.cancel'),
          type: "warning"
        })
      .then(function() {
        return delMenu(row.menuId);
      }).then(() => {
        proxy.getList();
        proxy.Success("删除成功");
      }).catch(() => {});
    },
    /**
     * 提交表单
     */
    submitForm(){
      formDataRef.value.validate(valid => {
        if (valid) {
          if (staticData.formData.menuId != undefined) {
            updateMenu(staticData.formData).then(response => {
              proxy.Success("修改成功");
              staticData.open = false;
              proxy.getList();
            });
          } else {
            addMenu(staticData.formData).then(response => {
              proxy.Success("新增成功");
              staticData.open = false;
              proxy.getList();
            });
          }
        }
      });
    },

    /**
     * 查询条件重置
     */
    resetSubmit(){
      staticData.dateRange=[]
      queryForm.value.resetFields();
      proxy.getList()
    },
    /**
     * 查询
     */
    querySubmit(){
      staticData.queryParams.pageNum = 1;
      proxy.getList()
    },
    handleSizeChange (val) {
      console.log(`${val} items per page`)
      staticData.queryParams.pageSize =val;
      proxy.getList()
    },
    handleCurrentChange(val){
      console.log(`current page: ${val}`)
      staticData.queryParams.pageNum =val;
      proxy.getList()
    }
   }
    return {
      Delete,
      Edit,
      Plus,
      Switch,
      Close,
      QuestionFilled,
      size,
      small,
      cancel,
      myTreeSelect,
      queryForm,
      formDataRef,
      ...methods,
      filterTableData,
      ...toRefs(staticData)
    }
}


})



</script>

<style scoped>
.demo-pagination-block + .demo-pagination-block {
margin-top: 10px;
}
.demo-pagination-block .demonstration {
margin-bottom: 16px;
}
</style>
<style scoped>
.app_content{
  
  margin-top: 30px;
  margin-left: 10px;
}
.mb8{
  margin-bottom: 10px;
}

</style>